Does map()
method mutate the original array?
Click to Reveal the Answer
No, the map()
method does not mutate the original array. It returns a new array with the results of calling a provided function on every element in the calling array.
const roadmaps = ['JavaScript', 'React', 'Node.js'];
const renamedRoadmaps = roadmaps.map((roadmap) => {
return `${roadmap} Roadmap`;
});
console.log(roadmaps); // ['JavaScript', 'React', 'Node.js']
console.log(renamedRoadmaps); // ['JavaScript Roadmap', 'React Roadmap', 'Node.js Roadmap']